<template>
  <div>
    <Row :gutter="32">
      <Col span="16">
      <div class="card-sty">
        <div class="title">{{ $t('promote.promotion_revenue') }}</div>
        <div class="le-title">
          {{ $t('promote.accumulated_income') }}
          <span class="currency">{{ userCurrency }}
            <span class="amount">{{ allData.cumulativeIncome || 0 }}</span>
          </span>
        </div>
        <div class="con-sty">
          <RingCom class="circle-sty" :data="circleData"></RingCom>
          <div class="legend-sty">
            <div class="list-legend">
              <div class="left">
                <div class="rect" style="background: #009BF2;"></div>
                <div class="label" style="color: #009BF2;">{{ $t('promote.level1_fre_commission') }}</div>
              </div>
              <div class="right">CNY {{ allData.firstLevelExpressCommission || 0 }}</div>
            </div>
            <div class="list-legend">
              <div class="left">
                <div class="rect" style="background: #B17EE1;"></div>
                <div class="label" style="color: #B17EE1;">{{ $t('promote.level2_fre_commission') }}</div>
              </div>
              <div class="right">CNY {{ allData.secondLevelExpressCommission || 0 }}</div>
            </div>
            <div class="list-legend">
              <div class="left">
                <div class="rect" style="background: #2FC089;"></div>
                <div class="label" style="color: #2FC089;">{{ $t('promote.commission_product_pro') }}</div>
              </div>
              <div class="right">CNY {{ allData.promoteGoodsBonus || 0 }}</div>
            </div>
            <div class="list-legend">
              <div class="left">
                <div class="rect" style="background: #FFA56B;"></div>
                <div class="label" style="color: #FFA56B;">{{ $t('promote.share_activity') }}</div>
              </div>
              <div class="right">CNY {{ allData.shareActivityBonus || 0 }}</div>
            </div>
          </div>
        </div>
      </div>
      </Col>
      <Col span="8">
      <div class="card-sty">
        <div class="title">{{ $t('promote.card_tit_balance') }}</div>
        <div class="sub-title">
          {{ $t('promote.card_sub_tit_balance') }}
          <Tooltip placement="top" transfer max-width="260">
            <Icon type="ios-help-circle-outline" size="20" color="#767B93" class="tip-icon" />
            <div slot="content" class="tip-text">{{ $t('promote.card_sub_tit_balance_tip') }}</div>
          </Tooltip>
        </div>
        <div class="balance-num">{{ allData.availableCommissionBalance }} <span>{{ userCurrency }}</span></div>
        <div class="sub-title">
          {{ $t('promote.card_third_tit_balance') }}
          <Tooltip placement="top" transfer max-width="260">
            <Icon type="ios-help-circle-outline" size="20" color="#767B93" class="tip-icon" />
            <div slot="content">{{ $t('promote.card_third_tit_balance_tip') }}</div>
          </Tooltip>
        </div>
        <div class="un-wd-num">{{ allData.unsettleCommissionBalance }} <span>{{ userCurrency }}</span></div>
        <div class="wd-btn" @click="wdMet">{{ $t('routerTitle.withdraw') }}</div>
      </div>
      </Col>
    </Row>

    <div class="fee-rect">
      <div class="title">{{ $t('promote.with_draw_balance_detail') }}</div>
      <div class="sel-sty">
        <div :class="item.isActive ? 'sel-text' : 'text'" v-for="item in selData" :key="item.name"
          @click="selectBtn(item.name)">
          {{ item.name }}
        </div>
      </div>
      <div class="table-sty">
        <Table :columns="columns" :data="changeData.records" class="my-table"></Table>
      </div>
      <pagination-com :totalPages="allPage" :currentPage="currentPage" @specifyMet="specifyMet"></pagination-com>
    </div>
    <!-- 详情抽屉 -->
    <draw-com ref="drawRef"></draw-com>
  </div>
</template>
<script>
import { mapState } from "vuex";
import { getWalletInfo, getWalletChangeInfo } from "@/api/invite";
import PaginationCom from './components/pagination-Com.vue';
import drawCom from "./components/draw-Com.vue";
import RingCom from "./components/ring-Com.vue";

export default ({
  components: { PaginationCom, drawCom, RingCom },
  data() {
    return {
      form: {
        pageNo: 1,
        pageSize: 7
      },
      selData: [
        { name: this.$t('user.all'), isActive: true },
        { name: this.$t('promote.expend_text'), isActive: false },
        { name: this.$t('promote.earning_text'), isActive: false }
      ],
      columns: [
        {
          title: this.$t('promote.trade_date'),
          key: 'tradeTime',
          width: 210,
          fixed: 'left',
          align: 'center'
        },
        {
          title: this.$t('promote.currency_type'),
          key: 'tradeType',
          width: 240,
          align: 'center',
          render: (h, params) => {
            switch (params.row.tradeType) {
              case 'COMMISSION_SETTLEMENT':
                return h('span', this.$t('personal.ShippingFees'));
              case 'GOODS_COMMISSION_SETTLEMENT':
                return h('span', this.$t('routerTitle.product_title_name'));
              case 'COMMISSION_BALANCE_QC_SHARE_ADD':
                return h('span', this.$t('promote.yel_tit_card'));
              case 'COMMISSION_WITHDRAW':
              case 'REFUND_COMMISSION_WITHDRAW':
                return h('span', this.$t('user.balanceWithdrawal'));
              case 'COMMISSION_BALANCE_MANUAL_ADD':
              case 'COMMISSION_BALANCE_MANUAL_SUB':
                return h('span', this.$t('promote.adjustment_of_balance'));
              default:
                return h('span', '');
            }
          }
        },
        {
          title: this.$t('user.status'),
          key: 'status',
          width: 220,
          align: 'center',
          render: (h, params) => {
            let statusText = '';
            let statusColor = '';
            switch (params.row.status) {
              case 0:
                statusText = this.$t('promote.status_in_hand');
                statusColor = '#FF9727';
                break;
              case 1:
                statusText = this.$t('promote.status_refused');
                statusColor = '#FF4D50';
                break;
              case 2:
                statusText = this.$t('user.completed');
                statusColor = '#32CB9D';
                break;
              case 3:
                statusText = this.$t('user.refunded_text');
                statusColor = '#FF4D50';
                break;
              default:
                statusText = '';
                statusColor = '';
            }
            return h('span', {
              style: {
                color: statusColor
              }
            }, statusText);
          }
        },
        {
          title: this.$t('user.amount'),
          key: 'tradeAmount',
          width: 200,
          align: 'center',
          render: (h, params) => {
            const amount = params.row.tradeAmount;
            const text = amount >= 0 ? `+${amount}` : amount;
            const color = amount >= 0 ? '#FF186B' : '#767B93';
            return h('span', {
              style: {
                color: color
              }
            }, text);
          }
        },
        {
          title: this.$t('personal.balance'),
          key: 'balanceAmount',
          width: 240,
          align: 'center'
        },
        {
          title: this.$t('promote.illustrate_text'),
          key: 'changeRmk',
          width: 240,
          align: 'center',
          render: (h, params) => {
            const text = params.row.changeRmk || '';
            return h('div', {
              style: {
                whiteSpace: 'nowrap',
                overflow: 'hidden',
                textOverflow: 'ellipsis',
                width: '100%'
              }
            }, text);
          }
        },
        {
          title: this.$t('routerTitle.details'),
          key: '',
          width: 240,
          align: 'center',
          render: (h, params) => {
            return h('div', {
              props: {
                type: 'text'
              },
              on: {
                click: () => {
                  this.look(params.row);
                }
              },
              style: {
                cursor: 'pointer' // 设置鼠标移入显示小手样式
              }
            }, this.$t('promote.look_text'));
          }
        },
      ],
      allData: {},
      changeData: {},
      circleData: [],
      allPage: 0,//总页数
      currentPage: 1,//当前页
    }
  },
  computed: {
    ...mapState({
      userCurrency: (state) => {
        return state.user.userCurrency.code;
      }
    }),
  },
  created() {
    this.getData();
    this.getChangeInfo();
  },
  methods: {
    selectBtn(name) {
      this.currentPage = 1;//重置当前页
      this.form.pageNo = 1;//重置查询页
      this.selData.forEach((item) => {
        if (item.name == name) {
          item.isActive = true
        } else {
          item.isActive = false
        }
      });

      if (name == this.$t('promote.earning_text')) {
        this.form.incomeExpenseType = 1;
      } else if (name == this.$t('promote.expend_text')) {
        this.form.incomeExpenseType = 2;
      } else {
        delete this.form.incomeExpenseType;
      }
      this.getChangeInfo();
    },
    look(info) {
      this.$refs.drawRef.open(info);
    },
    getData() {
      getWalletInfo().then(res => {
        this.allData = res.result;
        this.circleData.push({
          value: this.allData.firstLevelExpressCommission,
          name: this.$t('promote.level1_fre_commission')
        });
        this.circleData.push({
          value: this.allData.secondLevelExpressCommission,
          name: this.$t('promote.level2_fre_commission')
        });
        this.circleData.push({
          value: this.allData.promoteGoodsBonus,
          name: this.$t('promote.commission_product_pro')
        });
        this.circleData.push({
          value: this.allData.shareActivityBonus,
          name: this.$t('promote.share_activity')
        });
      })
    },
    getChangeInfo() {
      getWalletChangeInfo(this.form).then(res => {
        this.changeData = res.result;
        this.allPage = this.changeData.pages;
        this.currentPage = this.changeData.current;
        this.allAmount = this.changeData.total;
      })
    },
    wdMet() {
      this.$router.push(`/user/withdraw?type=commission`)
    },
    // 分页
    specifyMet(val) {
      this.form.pageNo = val;
      this.getChangeInfo();
    }
  }
})
</script>
<style lang="less" scoped>
.card-sty {
  padding: 40px 0;
  background: #FFFFFF;
  border-radius: 18px 18px 18px 18px;
  border: 1px solid #E8E8E8;

  .title {
    font-family: Open Sans, Open Sans;
    font-weight: 600;
    font-size: 24px;
    color: #1E1714;
    line-height: 28px;
    margin-left: 40px;
  }

  .le-title {
    font-family: PingFang SC, PingFang SC;
    font-weight: 500;
    font-size: 22px;
    color: #767B93;
    line-height: 26px;
    text-align: right;
    margin-bottom: 22px;
    margin-right: 64px;

    .currency {
      font-family: Open Sans, Open Sans;
      font-weight: bold;
      font-size: 21px;
      color: #FF186B;
      line-height: 25px;
      margin-left: 32px;
    }

    .amount {
      font-size: 28px;
      line-height: 32px;
    }
  }

  .con-sty {
    display: flex;
    align-items: center;
    gap: 40px;
    margin: 15px 64px 0 68px;

    .circle-sty {
      width: 205px;
      height: 205px;
    }

    .legend-sty {
      flex: 1;

      .list-legend {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-top: 26px;

        .left {
          display: flex;
          align-items: center;
          gap: 25px;

          .rect {
            width: 20px;
            height: 20px;
            min-width: 20px;
            max-width: 20px;
            min-height: 20px;
            max-height: 20px;
            border-radius: 2px 2px 2px 2px;
          }

          .label {
            font-family: Open Sans, Open Sans;
            font-weight: 400;
            font-size: 18px;
            line-height: 21px;
          }
        }

        .right {
          text-wrap: nowrap;
          font-family: Open Sans, Open Sans;
          font-weight: bold;
          font-size: 20px;
          color: #1E1714;
          line-height: 23px;
        }
      }
    }
  }

  .sub-title {
    font-family: PingFang SC, PingFang SC;
    font-weight: 400;
    font-size: 20px;
    color: #767B93;
    line-height: 23px;
    margin-bottom: 5px;
    margin-left: 40px;
    margin-right: 40px;
    margin-top: 28px;

    .tip-icon {
      cursor: pointer;
    }
  }

  .balance-num {
    font-family: Open Sans, Open Sans;
    font-weight: bold;
    font-size: 36px;
    color: #FF186B;
    line-height: 42px;
    margin-bottom: 18px;
    margin-left: 40px;
    margin-right: 40px;
    text-wrap: nowrap;

    span {
      font-size: 20px;
      line-height: 23px;
      margin-left: 8px;
    }
  }

  .un-wd-num {
    font-family: Open Sans, Open Sans;
    font-weight: bold;
    font-size: 22px;
    color: #1E1714;
    line-height: 26px;
    margin-left: 40px;
    margin-right: 40px;

    span {
      font-size: 16px;
      line-height: 19px;
    }
  }

  .wd-btn {
    padding: 13px 0;
    background: #FF186B;
    border-radius: 8px 8px 8px 8px;
    text-wrap: nowrap;
    font-family: PingFang SC, PingFang SC;
    font-weight: 600;
    font-size: 20px;
    color: #FFFFFF;
    line-height: 23px;
    text-align: center;
    margin-top: 26px;
    cursor: pointer;
    margin-left: 40px;
    margin-right: 40px;
  }
}

.fee-rect {
  padding: 32px 0;
  background: #FFFFFF;
  border-radius: 18px 18px 18px 18px;
  border: 1px solid #E8E8E8;
  margin-top: 38px;

  .title {
    font-family: Open Sans, Open Sans;
    font-weight: 600;
    font-size: 24px;
    color: #1E1714;
    line-height: 28px;
    margin-bottom: 27px;
    margin-left: 40px;
  }

  .sel-sty {
    display: flex;
    align-items: center;
    gap: 48px;
    margin-left: 55px;
    margin-bottom: 39px;

    .text {
      font-family: Open Sans, Open Sans;
      font-weight: 600;
      font-size: 20px;
      color: #767B93;
      line-height: 23px;
      padding: 8px 61px 8px 57px;
      cursor: pointer;
    }

    .text:hover {
      font-family: Open Sans, Open Sans;
      font-weight: 600;
      font-size: 20px;
      color: #000000;
      line-height: 23px;
      padding: 8px 61px 8px 57px;
      background: #F5F5F7;
      border-radius: 19px;
    }

    .sel-text {
      font-family: Open Sans, Open Sans;
      font-weight: 600;
      font-size: 20px;
      color: #000000;
      line-height: 23px;
      padding: 8px 61px 8px 57px;
      background: #F5F5F7;
      border-radius: 19px;
    }
  }

  .table-sty {
    margin: 0 56px;

    :deep(.ivu-table-fixed.ivu-table-fixed-shadow) {
      box-shadow: none;
    }
  }
}

:deep(.ivu-table-overflowX::-webkit-scrollbar) {
  // -webkit-appearance: none;
  width: 10px;
  height: 10px;
}

:deep(.ivu-table-tbody) {
  tr {

    td {
      height: 60px;
      border: none;

      .ivu-table-cell {
        font-weight: 500;
        font-size: 18px;
        color: #767B93;
        line-height: 19px;
      }
    }
  }
}

:deep(.ivu-table-header) {
  margin-bottom: 24px;

  thead {
    tr {
      th {
        background: none;
        padding: 0;
        padding-bottom: 24px;
        padding-top: 6px;

        .ivu-table-cell {
          font-family: PingFang SC, PingFang SC;
          font-weight: 500;
          font-size: 18px;
          color: #333333;
          line-height: 19px;
        }
      }
    }
  }
}

:deep(.ivu-table) {
  .ivu-table-fixed-header {
    margin-bottom: 24px;

    thead {
      tr {
        th {
          background: #FFFFFF;
          padding: 0;
          padding-bottom: 24px;
          padding-top: 6px;

          .ivu-table-cell {
            font-family: PingFang SC, PingFang SC;
            font-weight: 500;
            font-size: 18px;
            color: #333333;
            line-height: 19px;
          }
        }
      }
    }
  }
}
</style>
